const express = require('express')
const mysql = require("mysql")
let option = {
    host: 'localhost',
    port: '3306',
    user: 'root',
    password: 'password',
    database: 'book'
}

let con = mysql.createConnection(option)

con.connect((err) => {
    if (err) {
        console.log(err)
    } else {
        console.log('数据库开启连接')
    }
})

let app = express()

app.listen(3000)

app.get('/bookList', function (req, res) {
    let strSql = "select * from asyadminbook"
    con.query(strSql, (err, data) => {
        res.send(data)
    })
})
app.get('/bookInfo', function (req, res) {
    let bookName = req.query.bookName;
    let strSql = `select * from asyadminbook where bookName='${bookName}'`;
    con.query(strSql, (err, data) => {
        res.send(data)
    })
})
